import { _decorator, Component, Node, CCInteger, CCFloat, CircleCollider2D, CylinderColliderComponent, ITriggerEvent, Prefab, Vec3, BoxColliderComponent, CCBoolean, RigidBody } from 'cc';
import { poolManager } from '../../../../Framework/Scripts/Managers/poolManager';
import { ResMgr } from '../../../../Framework/Scripts/Managers/ResMgr';
import { SoundMgr } from '../../../../Framework/Scripts/Managers/SoundMgr';
import myUtil from '../../../../Framework/Scripts/Utils/myUtil';
import { OBJ_TYPE, PHY_GROUP } from '../../constant';
import { buildingCtrl } from '../buildingCtrl';
import { enemyBase } from '../enemyBase';
import { playerBase } from '../playerBase';
import { enemySkillBase } from './enemySkillBase';


//所有爆炸类的技能
const { ccclass, property } = _decorator;

@ccclass('boss_aoeBomb')
export class boss_aoeBomb extends enemySkillBase {



    @property({ type: CCFloat, displayName: "速度" })
    private speen: number = 1

    @property({ displayName: "是否持续伤害" })
    private isOnTriggerStay: boolean = false

    @property({ displayName: "是否播放动画" })
    private isOnAni: boolean = false

    @property({ displayName: "落地声音" })
    public soundName: string = "fireBallBig"










    private _colliderCom: BoxColliderComponent = null!;//




    onLoad() {

        this.node.active = false
        this._colliderCom = this.node.getComponent(BoxColliderComponent) 
    }


    onEnable() {
        // //   console.log("onEnable");

        if (this.isOnTriggerStay) {
            this._colliderCom.on("onTriggerStay", this._onTriggerEnterCb, this);

        } else {
            this._colliderCom.on("onTriggerEnter", this._onTriggerEnterCb, this);
        }

    }

    public init(howHit: Node) {
  
        this.howHit = null
        this.howHit = howHit

       
        
      
        SoundMgr.Instance.playSound(ResMgr.Instance.getAsset("Sounds",this.soundName))



        myUtil.playEffect(this.node, this.isOnAni, true, this.speen, true, 0)



    }

    onDisable() {
     
    }


    onDestroy() {
        if (this.isOnTriggerStay) {
            this._colliderCom.off("onTriggerStay", this._onTriggerEnterCb, this);

        } else {
            this._colliderCom.off("onTriggerEnter", this._onTriggerEnterCb, this);
        }
    }

    private _onTriggerEnterCb(event: ITriggerEvent) {

        
          
        const other: Node = event.otherCollider.node
        this.hit(other)
      
        if (this.hitNode) {
            //  console.log("击中特效");

            const hit: Node = poolManager.instance.getNode(this.hitNode, other.parent)
            const pos: Vec3 = this.node.getWorldPosition()
            hit.setWorldPosition(new Vec3(pos.x, 3, pos.z))
            myUtil.playEffect(hit, false, true, 1, true)
        }




    }
    update(dt: number) {


    }
}

